/* 
 * 底部JS加载
 */
$(function () {
    //获取回调
    $.getScript(base_url_www + 'ajax/getHtml', function () {
        if (ajaxhtml) {
            $("#for-message").html(ajaxhtml);
        }
    });
    
    //获取消息内容 
    $.ajax({
        type: 'GET',
        url: base_url_user + 'notices/ajax/myunreadnum',
        success: function (data) {
            if (data.success == true && data.number) {
                $('#dropdown_notices').remove();
                //有消息的时候宽度加大
                // $('._mynotices').parent().css('width','103px');
                $('._mynotices').append('<span style="color:#f90;"><b> (' + data.number + ') </b></span>');
                $('._mynotices').attr('href', base_url_user + 'notices/mymessage/unread');
                //$('.notices').append('<sup><i style="color:#f90;" class="fa fa-comment"></i></sup>')
                // $('.notices').append('<sup><img src="' + base_url + 'assets/img/new.gif"></sup>');
            }
        },
        cache: false
    });
    
    // //检测用户是否有发布过房源，提示变更为中介用户
    // $.ajax({
    //     type:'GET',
    //     url: base_url_www + 'user/checkhouse',
    //     success:function(data) {
    //         if(data) {
    //             qikoo.dialog.alert('由于网站升级，现只有中介身份可以发布房源！<br>系统检测到您有发布过房源，已将您的身份更改为中介身份！<br>如果您在组队中，您也会退出该组队！<br>不便之处，请谅解！',function(){
    //                 window.location.reload();
    //             });
                
    //             return false;
    //         }
            
    //     }
    // })
    
    //获取COOKIE
    function getCookie(name) {
        var value = "; " + document.cookie;
        var parts = value.split("; " + name + "=");
        if (parts.length == 2)
            return parts.pop().split(";").shift();
    }
    // //繁简转码
    window.onload = function () {
        //%E9%A6%99%E6%B8%AF == 香港
        if (getCookie('now_city_name') == '%E9%A6%99%E6%B8%AF' && getCookie('8now_lang') == '1') {
            TongWenWFU.setting = 0;
            TongWenWFU.toggle();
        }
    }

    $('.zh_hk').click(function () {
        TongWenWFU.setting = 0;
        TongWenWFU.toggle();
        var cookieName = '8now_lang';
        var cookieValue = '1';
        document.cookie = cookieName + "=" + cookieValue + ";expires=0" + ";domain=.roomie.hk;path=/";
    });

    $('.zh_cn').click(function () {
        TongWenWFU.setting = 1;
        TongWenWFU.toggle();
        var cookieName = '8now_lang';
        var cookieValue = '0';
        document.cookie = cookieName + "=" + cookieValue + ";expires=0" + ";domain=.roomie.hk;path=/";
    });
    //显示弹窗
    
    function dailypopupwindow() {
        $('#rp-record').text(parseInt($('#rp-record').text()) + parseInt(1));
        $('#popup').css('width', '210px');
        $('#popup').text("每日登陆获得 +1 信用分");
        $('#popup').stop(true, true).fadeOut();
        $('#popup').show();
        $('#popup').fadeOut(4000);
    }
    //FanyBox弹窗
    if ($(".fancybox").length) {
        $(".fancybox").fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
    }
    if (_dailypopupwindow == 'show')
        dailypopupwindow();

    $("body").append('<div><div><a href="#" class="gotop hide-for-small"></a></div><div><a href="#" class="android-download"><div><img /><a href="/8now.apk">点此下载</a></div></a></div><div></div></div>');
    //<--返回顶部代码
    $(window).scroll(function () {
        var t = document.documentElement.scrollTop || document.body.scrollTop;
        if (t > 20) {
            $(".gotop").fadeIn(200);
        } else {
            $(".gotop").fadeOut(200);
        }
    });
    //发送验证邮箱

    $(document).on("click", '#resend-validation-email-btn', function () {
        if ($(this).attr('disabled') != null) {
            return false;
        }
        $('.loading').css('display', 'inline-block');
        $.ajax({
            type: 'GET',
            url: base_url + 'user/resend_validation_email',
            dataType: 'JSONP',
            success: function (data) {
                $('.loading').hide();
                $('#resend-validation-email-btn').text('已发送');
                $('#resend-validation-email-btn').attr('disabled', '');
                // $('#resend-validation-email-btn').attr('href',data.email);
            },
            error: function (e) {
                $('.loading').hide();
                // $('#resend-validation-email-btn').attr('href',data.email);
            },
            cache: false
        });
    });

})